function fetchDataFromServer() {
	return new Promise((resolve) => {
		setTimeout(() => {
			resolve('使用服务器返回的数据');
		}, 3000);
	});
}

function fetchDatafromlocal() {
	return new Promise((resolve) => {
		setTimeout(() => {
			resolve('使用本地');
		}, 2000);
	});
}

function getFetchDataRes() {
	return Promise.race([fetchDataFromServer(), fetchDatafromlocal()]);
}

function fuzzySearchWithRegex(data, criteria) {
	return data.filter((item) => {
		return Object.keys(criteria).every((key) => {
			const value = item[key];
			const regex = new RegExp(criteria[key], 'i'); // 不区分大小写的正则表达式
			return value && regex.test(value);
		});
	});
}

export { getFetchDataRes, fuzzySearchWithRegex };
